﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HRM.Model;
using GalaSoft.MvvmLight.Ioc;

namespace HRM.ViewModel
{
    public class ProjectParticipantViewModel : ViewModelGeneric<ThamGiaDuAn>
    {
        private IProjectService _proService;

        public ProjectParticipantViewModel(IEntityService<ThamGiaDuAn> service, IProjectService proService)
            : base(service)
        {
            _proService = proService;
            Projects = _proService.GetByAll();
            if (Projects.Count > 0) ProjectSelected = Projects[0];
            if (SimpleIoc.Default.IsRegistered<NhanVien>()) Staff = SimpleIoc.Default.GetInstance<NhanVien>();
            else
            {
                throw new Exception("Staff not found");
            }
        }

        public NhanVien Staff { get; private set; }

        public string Title
        {
            get { return string.Format("Tham gia dự án - {0}", Staff.HoTen); }
        }

        public List<DuAn> Projects { get; private set; }

        private DuAn _projectSelected;

        public DuAn ProjectSelected
        {
            get { return _projectSelected; }
            set
            {
                if (_projectSelected != value)
                {
                    _projectSelected = value;
                    RaisePropertyChanged("ProjectSelected");
                }
            }
        }

        public override ThamGiaDuAn SelectedItem
        {
            get
            {
                return base.SelectedItem;
            }
            set
            {
                if (_selectedItem != value)
                {
                    _selectedItem = value;
                    if(_selectedItem != null) ProjectSelected = Projects.Find(x => x.MaDuAn == _selectedItem.MaDuAn);
                    RaisePropertyChanged("SelectedItem");
                }
            }
        }
    }
}
